package comp353Games;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JPanel;

/**
 * ClobberDisplay.java Offers the visual presentation of the game of Clobber.
 *
 * @author Andre Harvey, Deanna Finke, Tyler Radley
 * @version 3/25/12
 */
public class ClobberDisplay extends JPanel {

    //instance variables
    /**
     * The Clobber game this will display.
     */
    private Clobber game;

    /**
     * Class constructor.
     *
     * @param game The Clobber instance this will display.
     */
    public ClobberDisplay(GameModel game) {
        super(new BorderLayout());
        this.game = (Clobber) game;
        this.setOpaque(true);
    }

    @Override
    protected void paintComponent(Graphics graphics) {
        for (int i = 0; i < game.getRows(); i++) {
            for (int j = 0; j < game.getColumns(); j++) {
                graphics.setColor(Color.WHITE);
                graphics.fillRect(j * 40 + 125, i * 40 + 5, 40, 40);
                graphics.setColor(Color.WHITE);
                graphics.fillRect(j * 40 + 125, i * 40 + 5, 40, 40);
                graphics.setColor(Color.BLACK);
                graphics.drawRect(j * 40 + 125, i * 40 + 5, 40, 40);
                if (game.getClobberBoard()[i][j] == -1) {
                    graphics.setColor(Color.BLACK);
                    graphics.fillOval(j * 40 + 130, i * 40 + 10, 30, 30);
                } else if (game.getClobberBoard()[i][j] == 0) {
                    graphics.drawRect(j * 40 + 125, i * 40 + 5, 40, 40);
                } else {
                    graphics.setColor(Color.RED);
                    graphics.fillOval(j * 40 + 130, i * 40 + 10, 30, 30);
                }
            }
        }
    }

    @Override
    public Dimension getPreferredSize() {
        int width = 610;
        int height = 512;
        return new Dimension(width, height);
    }

    /**
     * Returns the preferred size for the status bar.
     *
     * @return A Dimension object representing the smallest size needed to
     * nicely display the status bar.
     */
    public Dimension getStatusBarPreferredSize(int size) {
        int width = 300 + 40 * game.getColumns();
        int height = 25;
        return new Dimension(width, height);
    }
}
